package org.yefei.homeworkday28.Three;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.*;
import java.util.Scanner;

public class ClientSide {

	public static void main(String[] args) {
		Socket s = null;
		try {
			s = new Socket("localhost", 8888);
			InputStream in = s.getInputStream();
			OutputStream os = s.getOutputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			PrintWriter pw = new PrintWriter(os);
			Scanner sc = new Scanner(System.in);
			System.out.println("********************************欢迎进入天气查询系统********************************");
			System.out.println("本系统提供以下功能：");
			while (true) {
				System.out.println("1、查询气温\t 2、查询风力\t 3、查询pm2.5\t 4、查询湿度\t 5、退出");
				System.out.println("请选择您想要查询的选项：");
				String ch = sc.next();
				pw.println(ch);
				pw.flush();
				String reply = br.readLine();
				if ("1".equals(ch) || "2".equals(ch) || "3".equals(ch) || "4".equals(ch))
					System.out.println("系统回复：" + reply);
				if ("5".equals(ch))
					break;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (s != null)
				try {
					s.close();
				} catch (IOException e) {
					e.printStackTrace();
				}

		}
	}

}
